<template>
    <view class="page" :style="'background: url(' + getCloudImg('common2/consume-bg.png') + ') no-repeat; background-size: 100% 100%;'">
        <view class="content">
            <image src="@/assets/img/common/title.png" class="title"></image>
            <view class="custom-input-wrap">
                <input v-model="form.username" type="text" :inputBorder="false" :maxlength="100" placeholder="请输入账号" class="custom-input" />
            </view>
            <view class="custom-input-wrap">
                <input v-model="form.password" type="text" :inputBorder="false" :maxlength="100" placeholder="请输入密码" class="custom-input" :password="showPassword" />
                <view class="show-password-box" @click="showPassword = !showPassword">
                    <image v-if="showPassword" src="@/assets/img/common/eye-open.png" class="w-24 h-24"></image>
                    <image v-else src="@/assets/img/common/eye-close.png" class="w-24 h-24"></image>
                </view>
            </view>
            <view class="pt-20">
                <view class="custom-button" @click="submit">登录</view>
            </view>
        </view>
    </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { login } from '@/service/consume'
import { loginStore } from '@/store/login'
import { toast, routerPush, isEmpty, getCloudImg } from '@/assets/js/utils'

onLoad(() => {})

const form = ref({
    username: '',
    password: '',
    loginType: 'WRITE_BA'
})

const showPassword = ref(true)

const submit = async () => {
    uni.showLoading({
        mask: true
    })
    let [result, err] = await login(form.value)
    uni.hideLoading()
    if (result) {
        toast('登录成功')
        await loginStore().login(result)
    }
}
</script>

<style lang="scss">
.page {
    min-height: 100vh;
}

.content {
    padding: 280rpx 88rpx 0 88rpx;

    .title {
        width: 352rpx;
        height: 123rpx;
        margin: 64rpx auto;
        display: block;
    }

    .custom-input-wrap {
        position: relative;
        margin-bottom: 40rpx;

        .custom-input {
            width: calc(574rpx - 32rpx * 2);
            height: 112rpx;
            background: #ffffff;
            border-radius: 12rpx;
            border: 1rpx solid #2e5f93;
            font-size: 32rpx;
            color: $primary;
            padding: 0 32rpx;
        }

        .show-password-box {
            width: 80rpx;
            height: 100rpx;
            background: #fff;
            position: absolute;
            right: 8rpx;
            top: 5rpx;
            z-index: 99;
            border-radius: 12rpx;
            display: flex;
            align-items: center;
            justify-content: center;
        }
    }
}
</style>
